package com.whg.shiro.controller;

import com.whg.shiro.domain.common.JsonData;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author whg
 * @create 2022/10/12 14:04
 * @description：
 */
@RestController
public class RolePermController {

    @RequestMapping("/role1")
    @RequiresRoles(value = {"admin","root"},logical = Logical.OR)
    public JsonData role1(){

        String msg = "拥有admin或root任一角色就可以访问的接口";

        return JsonData.buildSuccess(msg);
    }

    @RequestMapping("/role2")
    @RequiresRoles(value = {"admin","root"},logical = Logical.AND)
    public JsonData role2(){

        String msg = "同时拥有admin和root两个角色才可以访问的接口";

        return JsonData.buildSuccess(msg);
    }

    @RequestMapping("/perm1")
    @RequiresPermissions(value = {"video_update","video_delete"},logical = Logical.AND)
    public JsonData perm1(){

        String msg = "同时拥有video_update和video_delete两个权限才可以访问的接口";

        return JsonData.buildSuccess(msg);
    }

    @RequestMapping("/perm2")
    @RequiresPermissions(value = {"video_update","video_delete"},logical = Logical.OR)
    public JsonData perm2(){

        String msg = "拥有video_update和video_delete任一权限就可以访问的接口";

        return JsonData.buildSuccess(msg);
    }
}
